<?php 
defined("AT_EXE") or die ("CORE VARIABLE IS NOT DEFINED.");
class SaveResumeController extends Controller{
	private $emp_session ;
	private $can_session;
	public function __construct(){
		$this->calledClass(get_class($this));
		$this->emp_session = Session::get("employer");
		$this->can_session = Session::get("candidate");
	}
	public function load(){
		$resume = $this->loadModel("Resume");
		$saveresume = $this->loadModel("SaveResume");
		$category = $this->loadModel("Categorie");
		$membership = $this->loadModel("Membership");
		$employer = $this->loadModel("Employer");
		$gallery = $this ->loadModel("Gallery");
		 
		$emp_info = $employer->findObject(array("id="=>$this->emp_session["id"]));
		
		$this->set(array("employer"=>$emp_info));
		$this->set(array("emp_imgs"=>$gallery->findObject(array("id="=>$emp_info->img_id))));
		$this->set(array("ed"=>$this->get("ed"),"ex"=>$this->get("ex"),"s"=>$this->get("s"),"l"=>$this->get("l"),"c"=>$this->get("c")));
		$records = $resume->getList($this->get("page"),$this->get("perpage")?$this->get("perpage"):20,$this->get("search"),array("rem_name"),array("id"),"DESC");
		$checkMembership = array();
		$checkResumes = array();
		foreach ($records["records"] as $record){
			$checkMembership[] = $membership->findAsObject(array("user_id ="=>$this->emp_session["id"],"resume_id="=>$record->id));
		}
		foreach ($records["records"] as $record){
			$checkResumes[] = $saveresume->findAsObject(array("emp_id ="=>$this->emp_session["id"],"rem_id="=>$record->id));
		}
		$this->set(array("list"=>$records));
		$this->set(array("memberships"=>$checkMembership));
		$this->set(array("checkResumes"=>$checkResumes));
		$this->set(array("experiences"=>$category->getCategories(133)));
		$this->set(array("positions"=>$category->getCategories(150)));
		$this->set(array("locations"=>$category->getCategories(1)));
		$this->set(array("educations"=>$category->getCategories(138)));
		$this->set(array("category"=>$category->getCategories(23)));
		$this->set(array("getallcates"=>$saveresume->SelectC()));
		//$this->set(array("Getallcate"=>$GetCategory->SelectC()));
		$this->set(array("layout"=>"resume"));
		$this->render(array("employer"=>"admin"));
	}
	
	 public function savecv(){
		$resume = $this->loadModel("Resume");
		$category = $this->loadModel("Categorie");
		$rem = $this->loadModel("SaveResume");
		$id = $this->get("id");
		@$recordSaveResume = $this->model->findAsObject(array("rem_id ="=>$id,"emp_id="=>$this->emp_session["id"]));
		if($recordSaveResume == ""){
			echo 1;
			$this->model->save(array("rem_id"=>$id,"emp_id"=>$this->emp_session["id"],"save_date"=>date("Y-m-d H:i:s")));
		}
	} 
	
	public function displaycv(){
		$saveresume = $this->loadModel("SaveResume");
		$membership = $this->loadModel("Membership");
		$category = $this->loadModel("Categorie");
		$employer = $this->loadModel("Employer");
		$gallery = $this ->loadModel("Gallery");
			
		$emp_info = $employer->findObject(array("id="=>$this->emp_session["id"]));
		$this->set(array("employer"=>$emp_info));
		$this->set(array("emp_imgs"=>$gallery->findObject(array("id="=>$emp_info->img_id))));
		
		$this->set(array("experiences"=>$category->getCategories(133)));
		$this->set(array("positions"=>$category->getCategories(150)));
		$this->set(array("locations"=>$category->getCategories(1)));
		$this->set(array("educations"=>$category->getCategories(138)));
		$this->set(array("getallcates"=>$saveresume->SelectC()));
		
		$this->set(array("Getallcate"=>$saveresume->SelectC()));
		$list = $saveresume->getResumeInfo($this->emp_session["id"],$this->get("page"),$this->get("perpage")?$this->get("perpage"):20,$this->get("search"),array("id"));
		
		$chenckFollow = array();
		foreach ($list['records'] as $record){
			@$checkFollow[] = $membership->findAsObject(array("resume_id ="=>$record->rem_id,"user_id="=>$this->emp_session["id"]));
		}
		$this->set(array("list"=>$list));
		$this->set(array("chenckFollows"=>@$checkFollow));
		$this->set(array("layout"=>"viewcv"));
		$this->render(array("employer"=>"admin"));
	}
	
	public function Applyjob(){
		$this->render("Applyjob");
	}
	//searching resume on employer 
	public function searching(){
		$user = $this->loadModel("Resume");
		$saveresume = $this->loadModel("SaveResume");
		$category = $this->loadModel("Categorie");
		$membership = $this->loadModel("Membership");
		$employer = $this->loadModel("Employer");
		$gallery = $this ->loadModel("Gallery");
			
		$emp_info = $employer->findObject(array("id="=>$this->emp_session["id"]));
		$this->set(array("employer"=>$emp_info));
		$this->set(array("emp_imgs"=>$gallery->findObject(array("id="=>$emp_info->img_id))));
		$query = $saveresume->queryadvance();				  $this->set(array("ed"=>urldecode($this->get("ed")),"ex"=>urldecode($this->get("ex")),"s"=>urldecode($this->get("s")),"l"=>urldecode($this->get("l")),"c"=>urldecode($this->get("c"))));

		$records = $saveresume->DisplayAdmin($query,$this->get("page"),$this->get("perpage")?$this->get("perpage"):40,array("rem_educate"=>$this->get("ed"),
				"rem_experience_y"=>$this->get("ex"),"rem_location"=>$this->get("l"),"rem_position"=>$this->get("s"),"rem_cat"=>$this->get("c")),array("rem_createDate"),"ASC","AND");
		
		$checkMembership = array();
		$checkResumes = array();
		foreach ($records["records"] as $rocord){
			$checkMembership[] = $membership->findAsObject(array("user_id ="=>$this->emp_session["id"],"resume_id="=>$rocord->id));
		}
		foreach ($records["records"] as $rocord){
			$checkResumes[] = $saveresume->findAsObject(array("emp_id ="=>$this->emp_session["id"],"rem_id="=>$rocord->id));
		}
		
		$this->set(array("list"=>$records));
		$this->set(array("memberships"=>$checkMembership));
		$this->set(array("checkResumes"=>$checkResumes));
		$this->set(array("experiences"=>$category->getCategories(133)));
		$this->set(array("positions"=>$category->getCategories(150)));
		$this->set(array("locations"=>$category->getCategories(1)));
		$this->set(array("educations"=>$category->getCategories(138)));
		$this->set(array("category"=>$category->getCategories(23)));
		$this->set(array("getallcates"=>$saveresume->SelectC()));
		//$this->set(array("Getallcate"=>$GetCategory->SelectC()));
		$this->set(array("layout"=>"search"));
		$this->render(array("employer"=>"admin"));
	}
	
	public function delete(){
		$this->model->delete(array("rem_id = "=>$this->get("id"),"emp_id="=>$this->emp_session["id"]));
	}
	
	public function deleteresume(){
			$rem = $this->loadModel("SaveResume");
			$GetCategory = $this->loadModel("SaveResume");
			$category = $this->loadModel("Categorie");
			$education = $this->get("educat");
			$experiences = $this->get("experience");
			$locations = $this->get("locations");
			$positions = $this->get("positions");
			$this->set(array("Positions"=>$positions));
			$this->set(array("Locations"=>$locations));
			$this->set(array("Experience"=>$experiences));
			$this->set(array("Education"=>$education));
			
			$this->set(array("Experiences"=>$category->SelectQu(333)));
			$this->set(array("Position"=>$category->SelectQu(137)));
			$this->set(array("Location"=>$category->SelectQu(1)));
			$this->set(array("HighEducation"=>$category->SelectQu(143)));
			$this->set(array("Getallcate"=>$GetCategory->SelectC()));
			$rem->delete(array("id"=>$this->get("id")),true);
			echo"Delete are Success!!!!";
			$this->empsaveresumes();
	}
	
	public function getcan($ids){
		$query = "SELECT can_id  FROM Resumes WHERE id='$ids' ;";
		$result = parent::query($query);
		while($record = mysql_fetch_object($result)) $records = $record ;
		return $records->can_id;
	}
}
?>